package com.example.wechatlistview;

import android.graphics.Color;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.LinearLayout;

import androidx.annotation.ColorRes;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.example.wechatlistview.fragments.fg_chats;
import com.example.wechatlistview.fragments.fg_contacts;
import com.example.wechatlistview.fragments.fg_discover;
import com.example.wechatlistview.fragments.fg_me;
import com.example.wechatlistview.tools.CustomTools;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.lxj.xpopup.XPopup;

public class wechatlist extends AppCompatActivity {

    LinearLayout linearLayout;
    BottomNavigationView bottomNavigationView;
    @ColorRes
    int[] rootColor = {
            R.color.dimwhite, R.color.white
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        XPopup.setAnimationDuration(200);
        XPopup.setShadowBgColor(Color.parseColor("#00ffffff"));

        CustomTools.StatusBarFixer(wechatlist.this);
        setContentView(R.layout.activity_wechatlist);
        linearLayout = (LinearLayout) findViewById(R.id.main_root);
        bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottomNav);
        bottomNavigationView.setOnNavigationItemSelectedListener(navigationItemSelectedListener);

    }

    /**
     * 配置Fragment点击事件
     */
    private BottomNavigationView.OnNavigationItemSelectedListener navigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            FragmentManager fragmentManager = getSupportFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            Fragment f = null;
            int colorNow = rootColor[0];
            if (item.getItemId() == R.id.navigation_chats || item.getItemId() == R.id.navigation_contacts || item.getItemId() == R.id.navigation_discover || item.getItemId() == R.id.navigation_me) {
                /**
                 * 配置不同按钮下Fragment跳转
                 */
                switch (item.getItemId()) {
                    case R.id.navigation_chats:
                        colorNow = rootColor[0];
                        f = new fg_chats();
                        break;
                    case R.id.navigation_contacts:
                        colorNow = rootColor[0];
                        f = new fg_contacts();
                        break;
                    case R.id.navigation_discover:
                        colorNow = rootColor[0];
                        f = new fg_discover();
                        break;
                    case R.id.navigation_me:
                        colorNow = rootColor[1];
                        f = new fg_me();
                        break;
                    default:
                        break;
                }
                linearLayout.setBackgroundResource(colorNow);
                fragmentTransaction.replace(R.id.fragment, f);
                fragmentTransaction.commit();
                return true;
            } else {
                return false;
            }
        }
    };


}
